import 'package:flutter/cupertino.dart';
import 'package:wanAndroid/common/uts/sp_uts.dart';
import 'package:wanAndroid/common/uts/toast_uts.dart';
import 'package:wanAndroid/config/AppConfig.dart';
import 'package:wanAndroid/page/page_login.dart';

class StatusUts {
  StatusUts._();

  /// 判断是否登录
  static Future<bool> checkLogin() async {
    String u = await SPUts.getString(AppConfig.KEY_USER_NAME, "");
    String p = await SPUts.getString(AppConfig.KEY_USER_NAME, "");
    bool isLogin = await SPUts.getBoole(AppConfig.KEY_IS_LOGIN, false);
    return u.isNotEmpty && p.isNotEmpty && isLogin;
  }

  ///
  ///判断时是登录 forceLogin 是否签字登录
  static Future<bool> checkLogin2Login(BuildContext context) async {
    bool _isLogin = await checkLogin();
    if (!_isLogin) {
      //返回登录结果
      ToastUts.showToast(context, text: "请先登录···");
      _isLogin = await PageLogin.start(context);
    }
    return _isLogin;
  }
}
